home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / cqa.zip / REDIREC4.TC < prev    next >
Text File  |  1991-04-01  |  792b  |  30 lines

  1. QUESTION:  How do I change stdin or stdout to binary for redirection?
  2.  
  3. ANSWER:    The following code demonstrates a technique for accomplishing
  4.            this task:
  5.  
  6. #include <stdio.h>
  7. #include <io.h>
  8. #include <fcntl.h>
  9. #include <sys\stat.h>
  10.  
  11. /*
  12. ** It turns out there are 3 things that need to be done.
  13. ** Give the following a try:
  14. */
  15.  
  16. void main(void)
  17. {
  18. int     hndl = fileno( stdout );
  19. int     info = ioctl( hndl, 0 );
  20.  
  21. setmode( hndl, O_BINARY );              /* handle to binary mode */
  22. ioctl( hndl, 1, (info & 0xff) | 0x20 ); /* device to raw mode    */
  23. stdout->flags |= _F_BIN;                 /* stream to binary mode */
  24.  
  25. fputc('\n', stdout);
  26.  /* do what you need to do here */
  27.  
  28. ioctl( hndl, 1, info & 0xff );          /* put it back the way it was */
  29. }
  30.